//
//  ViewController.m
//  01-UIViewHomeWork
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//  登录界面

#import "ViewController.h"
#import "RegisterViewController.h"
#import "ForgetViewController.h"
#import "BaseTabBarController.h"
#import "HomePageViewController.h"
#import "AppDelegate.h"
#import "LoginView.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<LoginViewDelegate, UITextFieldDelegate>
@property (nonatomic, strong) LoginView *loginView;
@end

@implementation ViewController
/*
  Homework 1: 拉勾界面
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;
    [self creatLoginView];
}

- (void)creatLoginView {
    self.loginView = [[LoginView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    _loginView.delegate = self;
    [self.view addSubview:_loginView];
    [_loginView.userButton setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
    [_loginView.userButton setImage:[UIImage imageNamed:@"icon_username_select"] forState:UIControlStateSelected];
    _loginView.userTextField.placeholder = @"请输入已验证手机号或邮箱";
    _loginView.userTextField.delegate = self;
    [_loginView.passwordButton setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
    [_loginView.passwordButton setImage:[UIImage imageNamed:@"icon_password_select"] forState:UIControlStateSelected];
    _loginView.passwordTextField.placeholder = @"请输入密码";
    _loginView.passwordTextField.delegate = self;
    [_loginView.verfButton removeFromSuperview];
    [_loginView.forgetButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [_loginView.loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [_loginView.registerButton setTitle:@"注册" forState:UIControlStateNormal];
}

#pragma mark - LoginView协议方法
- (void)jumpViewController:(UIButton *)button {
    if ([button.titleLabel.text isEqualToString:@"注册"]) {
        RegisterViewController *regsiVC = [[RegisterViewController alloc] init];

        [self.navigationController pushViewController:regsiVC animated:NO];
    } else if ([button.titleLabel.text isEqualToString:@"随便逛逛"]) {
        // 设置tabBar为根控制器
        BaseTabBarController *baseTabBar = [[BaseTabBarController alloc] init];
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        app.window.rootViewController = baseTabBar;
    }
    else {
        ForgetViewController *forgetVC = [[ForgetViewController alloc] init];
        [self.navigationController pushViewController:forgetVC animated:YES];
    }
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField == _loginView.userTextField) {
        _loginView.userButton.selected = YES;
        _loginView.passwordButton.selected = NO;
        return YES;
    } else {
        _loginView.userButton.selected = NO;
        _loginView.passwordButton.selected = YES;
        return YES;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
